#ifndef ParseH264_h_
#define ParseH264_h_

#include <list>
#include <vector>
#include <memory>

class NALU_t
{
public:

	int startcodeprefix_len;      //! 4 for parameter sets and first slice in picture, 3 for everything else (suggested)
	unsigned len;                 //! Length of the NAL unit (Excluding the start code, which does not belong to the NALU)
	unsigned max_size;            //! Nal Unit Buffer size

	int forbidden_bit;            //! should be always FALSE
	int nal_reference_idc;        //! NALU_PRIORITY_xxxx
	int nal_unit_type;   

	// h265 头解析
	int LayerId;
	int Tid;

	char*  buf=NULL;//! NALU_TYPE_xxxx            //! contains the first byte followed by the EBSP
	unsigned short lost_packets;  //! true, if packet loss is detected

	int  bFrameType = 0; // 0-IDR , 1-P, -1 未知
};


class ParseH264
{
public:
	ParseH264();
	~ParseH264();

	int Init(char* path);
	// flags 0 264, 1 265, 2 特殊文件，前4个字节是标识是否是关键帧， 收四个字节是长度网络字节，后面是载荷
	int GetAnnexbNALU(NALU_t*& nalu, int flags = 0);

	// 返回聚合包，SPS PPS IDR 或者是 VPS SPS PPS IDR 在一次返回
	// mutBand 条带
	int GetAnnexbCompositeNALU(int flags, char *&p, int &len, bool &isKey, int mutBand = 1);
	// 重头播放
	int Reset();
	void Uinit();


private:

	FILE* bits = NULL;

	NALU_t m_nalu;

	int info2 = 0;
	int info3 = 0;
	int rtpnum = 0;
	unsigned char* Buf = NULL;

	std::vector< int8_t> m_buffer;
};

/*

int main()
{

	ParseH264 t_ParseH264;

	t_ParseH264.Init("./Remote.H264");
	int k = 0;

	std::vector< esPacket> t_vec;

	while (1)
	{
		NALU_t *t_Nalu= NULL;
		int ret = t_ParseH264.GetAnnexbNALU(t_Nalu);

		if (ret < 0)
		{
			break;
		}

		printf(" k : %d len: %6d  ", k++, t_Nalu->len);
		printf("nal_unit_type: %x\n", t_Nalu->nal_unit_type);

		printf("########### \n");
	}
	printf("test reades \n");

}


*/

#endif